package com.qcq.wecheck.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.qcq.wecheck.entity.Attendance;
import com.qcq.wecheck.dto.AttendanceCountDto;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * <p>
 * 签到记录表 Mapper 接口
 * </p>
 *
 * @author O
 * @since 2018-09-19
 */
@Component
public interface AttendanceMapper extends BaseMapper<Attendance> {
	/**
	 * 删除用户参与的签到活动(删除签到内容)
	 * 根据签到表的id和openId
	 *
	 * @param openId     id
	 * @param scheduleId id
	 * @return count deleted
	 */
	default Integer deleteHistory(Long scheduleId, String openId) {
		EntityWrapper<Attendance> wrapper = new EntityWrapper<>();
		wrapper.eq("schedule_id", scheduleId)
				.eq("open_id", openId);
		return this.delete(wrapper);
	}

	/**
	 * 根据日期段,openId和scheduleId获取特定考勤表的数量(考勤次数)
	 *
	 * @param scheduleId id
	 * @param openId     id
	 * @param from       from
	 * @param to         to
	 * @return list
	 */
	List<AttendanceCountDto> getAttendanceCountByDates(@Param(("openId")) String openId,
	                                                   @Param("scheduleId") Long scheduleId,
	                                                   @Param("from") String from,
	                                                   @Param("to") String to);

	/**
	 * 获取指定日期考勤情况列表
	 *
	 * @param date       date
	 * @param scheduleId id
	 * @param openId     id
	 * @return list
	 */
	List<Attendance> getByDate(@Param("openId") String openId,
	                                   @Param("scheduleId")Long scheduleId,
	                                   @Param("date")String date);
}
